<template>
  <div class="bid-info">
      <h3>
        招评标基本信息
        <el-button size="mini" @click="$router.push({name:'bidmgt'})">返回</el-button>
        <el-button size="mini" type="primary" @click="publish" v-if="status===1">发布</el-button>
        <el-button size="mini" type="primary" @click="publishCheck('审核')" v-if="status===2 && showVendorCheck">审核</el-button>
        <el-button size="mini" type="primary" @click="ruleSubmit" v-if="status===3">设置评标方法</el-button>
        <el-button size="mini" type="primary" @click="publishCheck('审核评标方法')" v-if="status===4 && showEvaluationCheck">审核评标方法</el-button>
      </h3>
      <div class="info-div">
          <div class="info-title">
              <span>招标信息 : {{infoData.psNo}}</span>
          </div>
          <div class="info-text w100">
              <span class="text-label">项目名称：</span>
              <span class="text-value">{{infoData.psTitle}}</span>
          </div>
          <div class="info-text">
              <span class="text-label">采购组织：</span>
              <span class="text-value">{{infoData.purOrgName}}</span>
          </div>
          <div class="info-text">
              <span class="text-label"> 采购组：</span>
              <span class="text-value">{{infoData.purGroupName}}</span>
          </div>
          <div class="info-text">
              <span class="text-label">招标负责人：</span>
              <span class="text-value">{{infoData.leaderUserName}}</span>
          </div>
          <div class="info-text">
              <span class="text-label">品类：</span>
              <span class="text-value">{{infoData.categoryName}}</span>
          </div>
          <div class="info-text">
              <span class="text-label">最小开标数量：</span>
              <span class="text-value">{{infoData.minOpenNum}}</span>
          </div>
          <div class="info-text">
              <span class="text-label">是否框架招标：</span>
              <span class="text-value">
                  {{infoData.isFrame == 1 ? '是' : '否'}}
              </span>
          </div>
          <div class="info-text">
              <span class="text-label">是否需保证金：</span>
              <span class="text-value">
                  {{infoData.isNeedBond == 1 ? '需要' : '不需要'}}
              </span>
          </div>
          <div class="info-text">
              <span class="text-label">是否开技术标：</span>
              <span class="text-value">
                   {{infoData.isNeedTecbidding == 1 ? '是' : '否'}}
              </span>
          </div>
          <div class="info-text w100">
              <span class="text-label">招标说明：</span>
              <span class="text-value" v-html="infoData.notice"></span>
          </div>
      </div>
      <div class="info-div">
          <div class="info-title">
              <span>招标时间</span>
          </div>
          <div class="info-text w50">
              <span class="text-label">
                  投标截止日期：
              </span>
              <span class="text-value">{{infoData.tenderEtimeStr}}</span>
          </div>
          <div class="info-text w50">
              <span class="text-label">
                  开标日期：
              </span>
              <span class="text-value">{{infoData.openTimeStr}}</span>
          </div>
      </div>


       <div class="info-div" v-if="status===4">
          <div class="info-title">
            <span>评标方法</span>
          </div>
          <div class="info-text w50">
            <span class="text-label">招标需求：</span>
            <span class="text-value">             
              <a href="javascript:;" @click="downloadFile(infoData.tenderFilePath,infoData.tenderFileName)" class="download_color">{{infoData.tenderFileName}}</a>
            </span>
          </div>
          <div class="info-text w50">
            <span class="text-label">技术评分方法：</span>
            <span class="text-value">{{infoData.tecUserDefinedAtt}}</span>
          </div>
          <div class="info-text w50">
            <span class="text-label">招标标书：</span>
            <span class="text-value">
                <a href="javascript:;" @click="downloadFile(infoData.tenderDemandPath,infoData.tenderDemandName)" class="download_color">{{infoData.tenderDemandName}}</a>
            </span>
          </div>
          <div class="info-text w50">
            <span class="text-label">商务评分方法：</span>
            <span class="text-value">{{infoData.bsUserDefinedAtt}}</span>
          </div>
      </div>



      <div class="info-div">
          <div class="info-title">
              <span>招标标的</span>
          </div>
        <el-table :data="tableData" border>
            <el-table-column label="供货区域" align="center" prop="purOrgName"></el-table-column>
            <el-table-column label="工厂" align="left" prop="factoryName" width="160px"></el-table-column>
            <el-table-column label="物料编码" align="center" prop="materialCode" width="120px"></el-table-column>
            <el-table-column label="物料名称" align="left" prop="materialName" width="160px"></el-table-column>
            <el-table-column label="型号/规格" align="center" prop="materialSpec"></el-table-column>
            <el-table-column label="单位" align="center" prop="stockUnit"></el-table-column>
            <el-table-column label="质保期" align="center" prop="qualityTime"></el-table-column>
            <el-table-column label="采购量" align="center" prop="planQty"></el-table-column>
            <el-table-column label="交期" align="center" prop="deliveryDate" width="100px"></el-table-column>
            <el-table-column label="备注" align="center" prop="remarks" width="200px"></el-table-column>
        </el-table>
      </div>
      <div class="info-div">
          <div class="info-title">
              <span>供应商</span>
          </div>
        <el-table :data="venderData" border>
            <el-table-column label="供应商编码" align="center" prop="vendorCode"></el-table-column>
            <el-table-column label="供应商名称" align="center" prop="vendorName"></el-table-column>
            <el-table-column label="地址" align="center" prop="regAddress"></el-table-column>
            <el-table-column label="未选择原因" align="center" prop="unselectedReason"></el-table-column>
        </el-table>
      </div>


      <el-dialog :title="dialogTitle" :visible.sync="checkVisible" class="dialog-form" width="500px">
        <div class="info-text w100">
            <span class="text-label">
                审核意见：
            </span>
            <span class="text-value">
                <el-input v-model="checkData.checkContent" type="textarea"></el-input>
            </span>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="()=>{checkData.checkStatus=1;checkTrue();}" :disabled="!checkData.checkContent">通过</el-button>
            <el-button @click="()=>{checkData.checkStatus=-1;checkTrue();}" :disabled="!checkData.checkContent">驳回</el-button>
        </div>
    </el-dialog>


    <el-dialog title="设置评标方法" :visible.sync="ruleVisible" width="600px">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="130px" class="demo-ruleForm">
          <el-form-item label="招标需求：" prop="tenderFilePath">
            <el-upload class="upload-file" ref="upload" :action="this.lib.config.host.system + '/common/fileupload/upload'" :data=fileData
              :limit="1" :on-success="res=>{uploadSuccess(res,'tenderFilePath')}" :file-list="fileList">
              <el-button slot="trigger" type="primary">选取文件</el-button>
            </el-upload>
          </el-form-item>
          <el-form-item label="招标标书：" prop="tenderDemandPath">
            <el-upload class="upload-file" ref="upload" :action="this.lib.config.host.system + '/common/fileupload/upload'" :data=fileData
              :limit="1" :on-success="res=>{uploadSuccess(res,'tenderDemandPath')}" :file-list="fileList">
              <el-button slot="trigger" type="primary">选取文件</el-button>
            </el-upload>
          </el-form-item>
          <el-form-item label="评标方法：" prop="tecUserDefined">
                <el-select v-model="ruleForm.tecUserDefined" placeholder="请选择" @change="ruleForm.autoevaMethod=''">
                    <el-option v-for="item in gradeTemplates" :key="item.id" :label="item.templateName" :value="item.id"></el-option>
                    <el-option :label="'自定义评标方法'" :value="'evaauto'"> </el-option>
                </el-select>
          </el-form-item>
          <el-form-item label="自定义评标方法：" prop="autoevaMethod" v-if="ruleForm.tecUserDefined==='evaauto'">
                <el-input type="textarea" v-model="ruleForm.autoevaMethod"></el-input>
          </el-form-item>
          <el-form-item label="商务评标方法：" prop="bsUserDefined">
                <el-select v-model="ruleForm.bsUserDefined" placeholder="请选择" @change="ruleForm.busautoevaMethod=''">                    
                    <el-option v-for="item in gradeTemplates" :key="item.id" :label="item.templateName" :value="item.id"></el-option>
                    <el-option :label="'自定义商务评标方法'" :value="'busevaauto'"> </el-option>
                </el-select>
          </el-form-item>
          <el-form-item label="自定义商务评标方法：" prop="busautoevaMethod" v-if="ruleForm.bsUserDefined==='busevaauto'">
                <el-input type="textarea" v-model="ruleForm.busautoevaMethod"></el-input>
          </el-form-item>
          <el-form-item>
            <!-- <el-button type="primary" @click="ruleSumbmitTrue(0)">暂存</el-button> -->
            <el-button type="primary" @click="ruleSumbmitTrue(1)">提交</el-button>
            <el-button @click="ruleVisible=false">取消</el-button>
          </el-form-item>
        </el-form>
    </el-dialog>
  </div>
</template>
<script>
import qs from 'qs';
  export default {
    props:['stepData'],
    data() {
      return {
            // 定义附件的业务模块和业务动作
        fileData: {
            busAction: "BID_SET_EVA_METHOD",
            tableName: "CT_PS_BID_MAIN_EXT",
            tableId: this.$route.query.id
        },
        checkId : '',
        lastNode : '',
        busCode : '',
        showVendorCheck : false,
        showEvaluationCheck : false,
        checkVisible:false,
        ruleVisible:false,
        dialogTitle:'',
        fileList:[],
        checkData:{
            checkStatus:1,
            checkContent:'',
        },
        ruleForm:{
            tenderFilePath:'',
            tenderDemandPath:'',
            tecUserDefined:'',
            bsUserDefined:''
        },
        rules: {
            tenderFilePath: [{
                required:true,
                message: '请上传招标标书',
                trigger: 'change'
            }],
            tenderDemandPath: [{
                required: true,
                message: '请上传招标需求',
                trigger: 'change'
            }],
            tecUserDefined: [{
                required: true,
                message: '请选择评标方法',
                trigger: 'change'
            }],
            bsUserDefined: [{
                required: true,
                message: '请选择商务评标方法',
                trigger: 'change'
            }],
            autoevaMethod: [{
                required: true,
                message: '请填写自定义评标方法',
                trigger: 'blur'
            }], 
            busautoevaMethod: [{
                required: true,
                message: '请填写商务自定义评标方法',
                trigger: 'blur'
            }],
        },
        infoData:{},
        tableData:[],
        venderData:[],
        gradeTemplates:[]
      };
    },
    computed:{
        status(){
            return this.stepData.bidMainDto.publishStatus===0
                || this.stepData.bidMainDto.publishStatus===3?1
                :this.stepData.bidMainDto.checkStatus===3?2
                :this.stepData.bidMainDto.ruleSubmitStatus===3?3
                :this.stepData.bidMainDto.ruleCheckStatus===3?4
                :5;
        }
    },
    created() {
        if(this.status == 2 || this.status == 4){
            this.busCode = 'vendorDidCheck';
            if(this.status == 4){
                this.busCode = 'evaluationBidCheck';
            }
            this.axios.post(this.lib.config.host.bidtender + '/common/flowcheck/checkAuth', {tableId : this.$route.query.id, tableName : 'BID_TENDER', busCode : this.busCode}).then((res)=>{
                if(res.data.success && res.data.resultMap.flag == 'true'){
                    if(this.status == 2){
                        this.showVendorCheck = true;
                    }else{
                        this.showEvaluationCheck = true;
                    }  
                    this.checkId = res.data.resultMap.checkId;
                    this.lastNode = res.data.resultMap.lastNode;
                }
                });
        }
      
    },
    mounted(){
        this.infoData=this.stepData.bidMainDto;
        this.tableData=this.stepData.bidMaterials;
        this.venderData=this.stepData.bidVendors; 
        this.axios.post(this.lib.config.host.bidtender + "/bidmgt/addition/findTemplates").then((res) => {
            if(res.data){
                this.gradeTemplates = res.data;
            }
        }).catch(function (error) {
            console.log(error);
        });
    },
    methods: {// 自动上传附件后返回附件url和name
        closeDialog(){
          this.checkVisible=false;
          this.ruleVisible=false;
        },
        uploadSuccess: function (response,type) {
            //附件上传成功回调
            this.ruleForm[type] = response.id;
        },
        publish(){
            this.$confirm('确认发布?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.axios.post(this.lib.config.host.bidtender + "/bidmgt/bid/publish/"+this.$attrs.data.id).then((res) => {
                    if(res.data.success){
                        this.$message.success('发布成功！');
                        this.$emit('initList');
                        this.closeDialog();
                    }
                })
            }).catch(() => {
                
            });            
        },
        publishCheck(title){
            this.checkData.checkContent='';
            this.dialogTitle=title;
            this.checkVisible=true;
        },
        checkTrue(){
                if(this.dialogTitle==='审核'){
                    this.axios.post(this.lib.config.host.bidtender + '/common/flowcheck/check', {id : this.checkId, checkStatus : this.checkData.checkStatus, option : this.checkData.checkContent}).then((res)=>{
                        if(res.data.success){
                            if((this.checkData.checkStatus == -1 && this.lastNode == 2) || this.lastNode == 1){
                                this.axios.post(`${this.lib.config.host.bidtender}/bidmgt/bid/publishCheck/${this.$attrs.data.id}`,qs.stringify(this.checkData)).then((res) => {
                                    if(res.data.success){
                                        this.$message.success(this.checkData.checkStatus===1?'审核成功':'已驳回！');
                                        this.$emit('initList');
                                        this.closeDialog();
                                    }
                                }).catch(function (error) {
                                    console.log(error);
                                });
                            }else{
                                this.$message.success(this.checkData.checkStatus===1?'审核成功':'已驳回！');
                                this.$emit('initList');
                                this.closeDialog();
                            }
                        }
                    });
            }else{

                this.axios.post(this.lib.config.host.bidtender + '/common/flowcheck/check', {id : this.checkId, checkStatus : this.checkData.checkStatus, option : this.checkData.checkContent}).then((res)=>{
                        if(res.data.success){
                            if((this.checkData.checkStatus == -1 && this.lastNode == 2) || this.lastNode == 1){
                                this.axios.post(`${this.lib.config.host.bidtender}/bidmgt/bid/checkEvaMethod/${this.$attrs.data.id}`,qs.stringify(this.checkData)).then((res) => {
                                    if(res.data.success){
                                        this.$message.success(this.checkData.checkStatus===1?'评标方法审核通过':'评标方法审核驳回！');
                                        this.$emit('initList');
                                        this.closeDialog();
                                    }
                                }).catch(function (error) {
                                    console.log(error);
                                });
                            }else{
                                this.$message.success(this.checkData.checkStatus===1?'评标方法审核通过':'评标方法审核驳回！');
                                this.$emit('initList');
                                this.closeDialog();
                            }
                        }
                    });
            }
        },
        ruleSubmit(){
            this.ruleVisible=true;
            this.$nextTick(()=>{
                this.resetForm('ruleForm');
            })
        },
        ruleSumbmitTrue(type){
            this.$refs['ruleForm'].validate((valid) => {
                if (valid) {
                    this.axios.post(`${this.lib.config.host.bidtender}/bidmgt/bid/submitEvaMethod/${this.$attrs.data.id}/${type}`,this.ruleForm).then((res) => {
                        if(res.data.success){
                            this.$emit('initList');
                            this.$message.success(type===1?'设置评标方法成功！':'暂存评标方法成功！');
                            this.closeDialog();
                        }
                    }).catch(function (error) {
                        console.log(error);
                    });
                }}
            )
        }
    }
  }

</script>
